<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
 <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
        <link rel="stylesheet" href="css/style.css"/>       
        <link rel="stylesheet" href="assets/css/ace.min.css" />
        <link rel="stylesheet" href="assets/css/font-awesome.min.css" />
        <link href="Widget/icheck/icheck.css" rel="stylesheet" type="text/css" />
		<!--[if IE 7]>
		  <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css" />
		<![endif]-->
        <!--[if lte IE 8]>
		  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
		<![endif]-->
	    <script src="js/jquery-1.9.1.min.js"></script>
        <script src="assets/js/bootstrap.min.js"></script>
<title>添加产品分类</title>
</head>
<body>
<div class="type_style">
 <div class="type_title">产品类型信息</div>
  
  <script>
  function sub1(){
	  var pcount=frm.pcount.value;
	  var name=frm.name.value;
	  var sort=frm.sortOrder.value;
	  checkName();
	  var typec=frm.typechecker.value;
	  if(typec!="0"){
		  return false;
	  }
	  if(sort==""){
		  frm.sortOrder.value="0";
	  }
	  sort=frm.sortOrder.value;
	  var SortReg=/^[1-9]\d{0,4}$/;
		if(!SortReg.test(sort)&&sort!="0"){
		alert("排序只能输入数字");
		return false;
		}else{
			 if(parseInt(sort)>parseInt(pcount)+1){
				  alert("排序数字不能大于本父类型的子类数量");
			  	  return false;
			  }
		}
	  $.ajax({
	        cache:true,
	        type: "POST",
	        url:'/goodtype/doAdd',
	        data:$('#form-user-add').serialize(),// 你的formid
	        async: false,
	        success:function(data) {
	        	if(data!=""){
	        		layer.msg('添加成功!',{icon: 1,time:1000});
	        		setTimeout(function(){//两秒后跳转  
	        			parent.location.href=data;
	        			$("#span").html("");
	                },1000);
	        	}else{
	        		alert('添加失败！');
	        	}
	        }
	    });
  }
  </script>
  <form  class="form form-horizontal" id="form-user-add" name="frm">
  <input type="hidden" name="pid" value="0"/>
  <input type="hidden" name="pcount" value="${PCount}"/>
  
 <div class="type_content">
  
    
    <div class="Operate_cont clearfix">
      <label class="form-label"><span class="c-red">*</span>分类名称：</label>
      <div class="formControls ">
        <input type="text" class="input-text" value="" placeholder="" id="user-name" name="TypeName">
        <input type="hidden" value="${typeD.name }" name="beforeName"/>
        <br/>
        <span id="span"></span>
        <div id="divc"><input type="hidden" name="typechecker" value="1"/></div>
      </div>
    </div>
     <script>
       function checkName(){
    	   if(frm.TypeName.value==""){
    		   $("#span").css('color','red');
	           $("#span").html("名称不能为空");
    		   frm.typechecker.value=1;
    		   return false;
    	   }
    	   var reg = new RegExp("^[A-Za-z0-9\u4e00-\u9fa5]+$");
    	   if(!reg.test(frm.TypeName.value)){
    		   $("#span").css('color','red');
	           $("#span").html("名称只能为中文，英文和数字");
    		   frm.typechecker.value=1;
    		   return false;
    	   }else{
    		   $("#span").html("");
    	   }
    	   
    			
    		   $.ajax({
    	   	        cache:true,
    	   	        type: "POST",
    	   	        url:'/goodtype/checkTypeName',
    	   	        data:$('#form-user-add').serialize(),// 你的formid
    	   	        async: false,
    	   	        error: function(request) {
    	   	            alert("Connection error");
    	   	        },
    	   	        success:function(data) {
    	   	        	if(data!="0"){
    	   	        		frm.typechecker.value=data;
    	   	        		$("#span").css('color','red');
    	   	        		$("#span").html("名称重复，不能使用相同类型");
    	   	        		
    	   	        	}else{
    	   	        		frm.typechecker.value=data;
    	   	        		$("#span").css('color','green');
    	   	        		$("#span").html("名称可以使用");
    	   	        	}
    	   	        }
    	   	    });
    	    	   
    		   
    	   
    	   
       }
       </script>
        <div class="Operate_cont clearfix">
      <label class="form-label"><span class="c-red">*</span>排序：</label>
      <div class="formControls ">
        <input type="text" class="input-text" value="0" placeholder="" id="user-name" name="sortOrder">
      </div>
      <div style="color:grey">0为系统默认排序，最大不超过${PCount+1}</div>
    </div>
  </div>
    <div class="">
     <div class="" style=" text-align:center">
      <input class="btn btn-primary radius" type="button" onclick="javascript:sub1()" value="确认添加">
      </div>
    </div>
  </form>
  </div>
<script type="text/javascript" src="Widget/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="Widget/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript" src="assets/layer/layer.js"></script>
<script type="text/javascript" src="js/H-ui.js"></script> 
<script type="text/javascript" src="js/H-ui.admin.js"></script>
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-user-add").Validform({
		tiptype:2,
		callback:function(form){
			form[0].submit();
			var index = parent.layer.getFrameIndex(window.name);
			parent.$('.btn-refresh').click();
			parent.layer.close(index);
		}
	});
});
</script>
</body>
</html>